<template>
  <div>
    <Form :label-width="140" ref="form" :model="formData" :rules="formDataRules">
      <Card title="新增验收事项" dis-hover class="ivu-mt">
        <Row>
          <Col span="18" offset="2">
          <FormItem label="验收事项名称" prop="itemName">
            <Input v-model.trim="formData.itemName" placeholder="请输入验收事项名称" maxlength="100"></Input>
          </FormItem>
          </Col>
          <Col span="18" offset="2">
            <FormItem label="检验类型" prop="itemType">
              <Select v-model="formData.itemType" filterable>
                <Option v-for="item in brandList" :value="item.value" :key="item.value">{{ item.label }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="18" offset="2">
          <FormItem label="">
            <Button type="primary" :loading="rLoading" @click="toRelease('form')">提交</Button>
            <Button @click="goBack" class="ivu-ml">取消</Button>
          </FormItem>
          </Col>
        </Row>
      </Card>
    </Form>
  </div>
</template>
<script>
  import { ApiRequest } from '@api/basePage'
  export default {
    data() {
      return {
        rLoading:false,
        pickerOptions: {
          disabledDate(date) {
            return date && date.valueOf() < Date.now() - 86400000;
          },
        },
        brandList: [{
            value: '1',
            label: '数值'
          },
          {
            value: '2',
            label: '文本'
          }],
        showAreaNames: '',
        salableAreaData: [],
        areaNames: [],
        cityUuids: [],
        productDetailImages: [], //图片回显
        formData: {
          itemName: '',
          itemType: '', //验收事项类型1数字2文本
          enable: 1
        },
        formDataRules:{
          itemName:[
            {required: true, message: '请输入验收事项名称', trigger: 'blur'}
          ],
          itemType:[
            {required: true, message: '请选择检验类型', trigger: 'blur'}
          ]
        },
        requestApi: { // 视情况自定义
          // 新增品牌
          baseAdd: {
            url: '/sysback/acceptitem/acceptitem/baseAdd', // 接口地址
            type: 'post' // 接口请求类型
          },
        },
      }
    },
    methods: {
      //保存按钮
      toRelease(name) {
        this.$refs[name].validate(valid => {
          if (valid) {
            this.rLoading = true;
            ApiRequest(this.requestApi.baseAdd.url, this.requestApi.baseAdd.type, this.formData, false).then(res => {
              if (res.retStatus === '1') {
                this.$Message.success('新增成功!');
                this.$router.go(-1);
              }
              this.rLoading = false;
            })
          }
        })
      },
      goBack() {
        this.$router.go(-1);
      }
    }
  }
</script>
<style lang="less" scoped>
</style>
